<template>
  <a-row :gutter="10">
    <a-col :span="24">
  <a-card :bordered="false">
    <!-- 查询区域 -->
<!--    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
&lt;!&ndash;          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="订单号">
              <a-input placeholder="请输入名称" v-model="queryParam.orderCode"></a-input>
            </a-form-item>
          </a-col>&ndash;&gt;
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
&lt;!&ndash;              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>&ndash;&gt;
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>-->
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">收票登记</a-button>
      <a-button @click="handleOrderDetailList" type="primary" icon="plus">订单明细</a-button>
      <a-button @click="handleDetailList" type="primary" icon="plus">收货明细</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('收票管理')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
      <!-- 高级查询区域 -->
      <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        class="j-table-force-nowrap"
        :scroll="{x:true}"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        :customRow="clickThenSelect"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text,record">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" :preview="record.id" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <ticket-collection-management-modal ref="modalForm" @ok="modalFormOk"/>
    <ticket-collection-management-order-detail-modal ref="orderDetail"></ticket-collection-management-order-detail-modal>
    <TicketCollectionManagementDetailModal ref="detail"></TicketCollectionManagementDetailModal>
  </a-card>
    </a-col>
    <a-col :span="24">
      <a-card :bordered="false">
        <a-tabs defaultActiveKey="1">
          <a-tab-pane tab="收票信息" key="1">
            <a-table
              ref="table"
              size="middle"
              bordered
              rowKey="id"
              class="j-table-force-nowrap1"
              :scroll="{x:true}"
              :columns="detail.columns"
              :dataSource="detail.dataSource"
              :rowSelection="{selectedRowKeys: detail.selectedRowKeys, onChange: onSelectDetailChange}"
              :loading="loading">
              <template slot="fileSlot" slot-scope="text">
                <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
                <div v-else>
                  <a-button
                    :ghost="true"
                    type="primary"
                    icon="download"
                    size="small"
                    @click="downloadFile(text)"
                    style="margin-right: 8px;">
                    下载
                  </a-button>
                  <a-button
                    :ghost="true"
                    type="primary"
                    icon="eye"
                    size="small"
                    @click="handlePreviewFile(text)">
                    预览
                  </a-button>
                </div>
              </template>
            </a-table>
          </a-tab-pane>
        </a-tabs>
      </a-card>
    </a-col>
  </a-row>
</template>

<script>

  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import TicketCollectionManagementModal from './modules/TicketCollectionManagementModal'
  import {filterMultiDictText} from '@/components/dict/JDictSelectUtil'
  import '@/assets/less/TableExpand.less'
  import { getAction } from '@api/manage'
  import TicketCollectionManagementOrderDetailModal
    from '@views/business/procurement/modules/TicketCollectionManagementOrderDetailModal.vue'
  import TicketCollectionManagementDetailModal
    from '@views/business/procurement/modules/TicketCollectionManagementDetailModal.vue'
  import { JVXETypes } from '@comp/jeecg/JVxeTable'
  import { FilePreview } from '@/utils/tslCommon'
  export default {
    name: "TicketCollectionManagementList",
    mixins:[JeecgListMixin],
    components: {
      TicketCollectionManagementOrderDetailModal,
      TicketCollectionManagementModal,
      TicketCollectionManagementDetailModal
    },
    data () {
      return {
        ipagination: {
          current: 1,
          pageSize:10 ,
          pageSizeOptions: ['10', '20', '30'],
          showTotal: (total, range) => {
            return range[0] + "-" + range[1] + " 共" + total + "条"
          },
          showQuickJumper: true,
          showSizeChanger: true,
          total: 0
        },
        description: '收票管理管理页面',
        // 表头
        columns:[
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'采购订单',
            align:"center",
            dataIndex: 'orderCode'
          },
          {
            title:'单据类型',
            align:"center",
            dataIndex: 'type_dictText'
          },
          {
            title:'供应商名称',
            align:"center",
            dataIndex: 'supplierName'
          },
          {
            title:'订单金额',
            align:"center",
            dataIndex: 'orderAmount'
          },
          {
            title:'收货金额',
            align:"center",
            dataIndex: 'receiptNum'
          },
          {
            title:'已收票金额',
            align:"center",
            dataIndex: 'receiveTicketNum'
          },
          {
            title:'未收票金额',
            align:"center",
            dataIndex: 'unpaidTicketNum'
          },
          {
            title:'收票状态',
            align:"center",
            dataIndex: 'ticketStatus_dictText'
          },
          {
            title:'制单人',
            align:"center",
            dataIndex: 'createBy'
          },
          {
            title:'制单部门',
            align:"center",
            dataIndex: 'sysOrgCode'
          },
          {
            title:'制单时间',
            align:"center",
            dataIndex: 'createTime'
          },
        ],
        detail:{
          selectedRowKeys: [],
          selectionRows:[],
          dataSource:[],
          ipagination: {
            current: 1,
            pageSize: 30,
            pageSizeOptions: ['10', '30', '100'],
            showTotal: (total, range) => {
              return range[0] + '-' + range[1] + ' 共' + total + '条'
            },
            showQuickJumper: true,
            showSizeChanger: true,
            total: 0,
          },
          columns: [
            {
              title: '#',
              dataIndex: '',
              key:'rowIndex',
              width:60,
              align:"center",
              customRender:function (t,r,index) {
                return parseInt(index)+1;
              }
            },
            {
              title:'订单编号',
              align:"center",
              dataIndex: 'orderCode'
            },
            {
              title:'发票号',
              align:"center",
              dataIndex: 'ticketCode'
            },
            {
              title:'发票类型',
              align:"center",
              dataIndex: 'ticketType_dictText'
            },
            {
              title:'发票金额',
              align:"center",
              dataIndex: 'ticketMoney'
            },
            {
              title:'开票日期',
              align:"center",
              dataIndex: 'ticketDate',
              customRender:function (text) {
                return !text?"":(text.length>10?text.substr(0,10):text)
              }
            },
            {
              title:'订单分配金额',
              align:"center",
              dataIndex: 'allocationNum'
            },
            {
              title:'登记人',
              align:"center",
              dataIndex: 'createBy'
            },
            {
              title:'登记时间',
              align:"center",
              dataIndex: 'createTime'
            },
            {
              title:'备注',
              align:"center",
              dataIndex: 'remark'
            },
            {
              title:'附件',
              align:"center",
              dataIndex: 'fileUrl',
              scopedSlots: {customRender: 'fileSlot'}
            },
          ],},

        url: {
          list: "/procurement/ticketCollectionManagement/list",
          delete: "/procurement/ticketCollectionManagement/delete",
          deleteBatch: "/procurement/ticketCollectionManagement/deleteBatch",
          exportXlsUrl: "/procurement/ticketCollectionManagement/exportXls",
          importExcelUrl: "procurement/ticketCollectionManagement/importExcel",

        },
        dictOptions:{},
        superFieldList:[],
      }
    },
    created() {
      this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      }
    },
    methods: {
      handlePreviewFile(row) {
        console.log("22222222")
        console.log("222222",row)
        FilePreview(row);
      },
      handlePreviewReviewDesFiles(row) {
        console.log(row)
        if (row && row.filePath) {
          FilePreview(row.filePath.split('_')[0])
        }
      },
      handleOrderDetailList(){
        const row = this.selectionRows
        if(row.length===0){
          return this.$message.warning('请选择一条数据')
        }
        this.$nextTick(() => {
          this.$refs.orderDetail.detail(row)
        })
      },
      handleDetailList(){
        const row = this.selectionRows
        if(row.length===0){
          return this.$message.warning('请选择一条数据')
        }
        this.$nextTick(() => {
          this.$refs.detail.detail(row)
        })
      },
      handleAdd() {
        if(!this.selectedRowKeys.length>0){
          return this.$message.warning("请选择一条记录")
        }
        console.log("11111111111111",this.selectionRows)
        this.$refs.modalForm.add(this.selectionRows);
        this.$refs.modalForm.title = "新增";
        this.$refs.modalForm.disableSubmit = false;
      },
      clickThenSelect(record){
        return {
          onClick:()=>{
            this.onSelectChange(record.id.split(","), [record]);
          }
        }
      },
      onSelectChange(selectedRowKeys, selectionRows) {
        this.selectedRowKeys = selectedRowKeys;
        this.selectionRows = selectionRows;
        console.log(this.selectedRowKeys,this.selectionRows)
        this.detail.dataSource=[]
        let ids = selectedRowKeys.join(",")
        console.log("222131",ids)
        getAction('/procurement/ticketCollectionManagement/selectTicketDetailByOrderId',
          {orderId:ids}).then(res=>{
          if (res.success){
            this.detail.dataSource=res.result
          }
        })
      },
      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'ticketType',text:'发票类型',dictCode:'ticket_type'})
        fieldList.push({type:'string',value:'ticketCode',text:'发票号',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'ticketMoney',text:'发票金额',dictCode:''})
        fieldList.push({type:'date',value:'ticketDate',text:'开票日期'})
        fieldList.push({type:'string',value:'fileUrl',text:'附件',dictCode:''})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>